package com.kawa.kemanage.controller.api;

import com.kawa.kemanage.service.NewsFavoritesService;
import com.kawa.kemanage.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/api/favorites")
public class NewsFavoritesContrller {
    @Autowired
    private NewsFavoritesService newsFavoritesService;

    // 添加收藏  ？？
//    @PostMapping("/add/{userId}/{contentId}")
//    public Result addFavorite(@PathVariable Integer userId, @PathVariable Integer contentId) {
//        if (newsFavoritesService.addFavorite(userId, contentId)) {
//            return Result.success("收藏成功");
//        }
//        return Result.error("收藏失败");
//    }

    // 取消收藏（通过用户ID和内容ID） ？？
//    @PostMapping("/cancel/{userId}/{contentId}")
//    public Result cancelFavorite(@PathVariable Integer userId, @PathVariable Integer contentId) {
//        if (newsFavoritesService.cancelFavoriteByUserAndContent(userId, contentId)) {
//            return Result.success("取消收藏成功");
//        }
//        return Result.error("取消收藏失败");
//    }


    // 获取收藏数量（不准改）
    @GetMapping("/getFavoritesCount/{content_id}")
    public Result getFavoritesCount(@PathVariable Integer content_id) {
        return Result.success(newsFavoritesService.getFavoritesCount(content_id));
    }

    //取消收藏(不准改）
    @PostMapping("/delectFavorites/{favorite_id}")
    public  Result delectFavorites(@PathVariable Integer favorite_id){
        if (newsFavoritesService.delectfavorites(favorite_id)){
            return Result.success("取消收藏成功");
        }else {
            return Result.error("取消收藏失败");
        }
    }
}
